#include "campaign.h"


#include <QDebug>


Campaign::Campaign(const QString &name, QObject *parent) :
    DTwentyItem(name, parent)/*,
    d(new Data())*/
{
    qRegisterMetaType<SkillContainer*>("Skills");
    qRegisterMetaType<SpecialAbilityContainer*>("Special Abilities");
    qRegisterMetaType<CharacterClassContainer*>("Character Classes");
}

Campaign::Campaign(const Campaign &other) :
    DTwentyItem(other)/*,
    d(other.d)*/
{
    qRegisterMetaType<SkillContainer*>("Skills");
    qRegisterMetaType<SpecialAbilityContainer*>("Special Abilities");
    qRegisterMetaType<CharacterClassContainer*>("Character Classes");
}

int Campaign::fieldCount() const
{
    int ret = 0;
    foreach(const DTwentyItem* item, findChildren<DTwentyItem*>())
    {
        int fields = item->fieldCount();
        if (ret < fields)
        {
            ret = fields;
        }
    }
    return ret;
}

void Campaign::initialize()
{
    skillsContainer();
    specialsContainer();
    classContainer();

    onChanged(false);

    connect(this, SIGNAL(sigChanged()), this, SLOT(onChanged()), Qt::UniqueConnection);
}

bool Campaign::changed() const
{
    return m_changed;
}


SkillContainer *Campaign::skillsContainer()
{
    SkillContainer* skills = findChild<SkillContainer*>("Skills");
    if (!skills)
    {
        skills = new SkillContainer("Skills", this);
        skills->setObjectName("Skills");
    }

    return skills;
}

SpecialAbilityContainer *Campaign::specialsContainer()
{
    SpecialAbilityContainer* specials = findChild<SpecialAbilityContainer*>();
    if (!specials)
    {
        return new SpecialAbilityContainer(this);
    }
    return specials;
}

CharacterClassContainer *Campaign::classContainer()
{
    CharacterClassContainer* characterClasses = findChild<CharacterClassContainer*>("Classes");
    if (!characterClasses)
    {
        characterClasses = new CharacterClassContainer("Character Classes", this);
        characterClasses->setObjectName("Classes");
    }

    return characterClasses;
}


void Campaign::onChanged(bool changed)
{
    m_changed = changed;
}

